package com.craftcomputing.client.SearchResult.Label;

import com.craftcomputing.client.Entry.EntryPanel;
import com.craftcomputing.client.Listeners.SearchResultLabelListeners.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.json.client.JSONValue;

abstract public class SearchResultLabel extends Composite {

	protected String name = "Example Code Entry";
	protected String imageLoc = "mainimages/01_11a.jpg";
	private Label label;
	private FocusPanel focusPanel;
	private HorizontalPanel hp_1; 	
	/**
	* @wbp.parser.constructor
	*/
	public SearchResultLabel() {
		makeWidget();
    	focusPanel.addMouseListener(new SearchResultLabelMouseListener(this, hp_1));
	}
	public SearchResultLabel(JSONValue json) {
		fillData(json);
		makeWidget();
		setWidth("796px");
		//setStyleName("gwt-Result");
    	//label.addMouseListener(new SearchResultLabelMouseListener(this, label, json));
    	focusPanel.addMouseListener(new SearchResultLabelMouseListener(this, hp_1));
    	focusPanel.addClickListener(new SearchResultLabelClickListener(this, json));
	}
	public void makeWidget() {
		focusPanel = new FocusPanel();
		initWidget(focusPanel);

    	hp_1 = new HorizontalPanel();
		hp_1.setStyleName("gwt-Result");
		focusPanel.add(hp_1);
		//initWidget(hp_1);
		hp_1.setHeight("60px");
		final Image im_1 = new Image("image/thumb?path=/"+imageLoc);
		im_1.addLoadListener(new ImageLoadListener(im_1));
        im_1.setSize("60px", "60px");
		hp_1.add(im_1);

    	final HorizontalPanel horizontalPanel = new HorizontalPanel();
    	hp_1.add(horizontalPanel);
    	hp_1.setCellWidth(horizontalPanel, "100%");
    	horizontalPanel.setWidth("100%");
    	horizontalPanel.setSpacing(2);
    	label = new Label(name);
    	horizontalPanel.add(label);
    	label.setHeight("60px");
    	label.setStyleName("gwt-SearchResultLabel");

	}
	abstract protected void fillData(JSONValue json);
	abstract public EntryPanel makeEntryPanel();
}
